package czk.concrent.juc.countDOwnLatch.current;

import java.util.concurrent.CountDownLatch;

/**
 * 模拟并发编程
 *
 * @Author:ChenZhangKun
 * @Date: 2021/9/1 10:55
 */
public class ModifyConcurrent {
    public static void main(String[] args) {
        // 定义五个线程
        CountDownLatch countDownLatch = new CountDownLatch(5);
        //
        for (int i = 0; i < 5; i++) {
            int j = i;
            new Thread(() -> {
                try {
                    // 阻塞线程
                    countDownLatch.await();
                    // 输出
                    // 1630465127758Thread-0输出了：0
                    // 1630465127758Thread-1输出了：1
                    // 1630465127758Thread-2输出了：2
                    // 1630465127758Thread-4输出了：4
                    // 1630465127758Thread-3输出了：3
                    System.out.println(System.currentTimeMillis() + Thread.currentThread().getName() + "输出了：" + j);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }).start();
            countDownLatch.countDown();
        }
    }
}
